<?php

class RequestController extends Controller {

    public function actionIndex() {
        $this->render('index');
    }

    public function actionValidar() {
        if (isset($_POST['txtUsuario'], $_POST['txtContrasena'])) {
            
            if(Yii::app()->params['auditoria'])
                parent::auditoria ("Sesion intento " . $_POST['txtUsuario'],0);
            
            $model = new LoginForm;
            $model->username = $_POST['txtUsuario'];
            $model->password = $_POST['txtContrasena'];
            
            if ($model->validate() && $model->login()) {
                
                if(Yii::app()->params['auditoria'])
                    parent::auditoria ("Sesion inicio exitoso ",$model->idUsuario);
                
                $this->redirect(array('site/index', 'idu' => $model->idUsuario, 'hash' => $model->hash));
            } else {
                
                if(Yii::app()->params['auditoria'])
                    parent::auditoria ("Sesion NO exitoso " . $_POST['txtUsuario'], 0);
                
                $this->redirect(array('site/index', 'error' => '1'));
            }
        }
    }
    
    public function actionLogout() {
        if(Yii::app()->params['auditoria'])
                    parent::auditoria ("Sesion cierre exitoso ",$_REQUEST['idu']);
        Yii::app()->user->logout();
        $this->redirect(Yii::app()->homeUrl);
    }

    // Uncomment the following methods and override them if needed
    /*
      public function filters()
      {
      // return the filter configuration for this controller, e.g.:
      return array(
      'inlineFilterName',
      array(
      'class'=>'path.to.FilterClass',
      'propertyName'=>'propertyValue',
      ),
      );
      }

      public function actions()
      {
      // return external action classes, e.g.:
      return array(
      'action1'=>'path.to.ActionClass',
      'action2'=>array(
      'class'=>'path.to.AnotherActionClass',
      'propertyName'=>'propertyValue',
      ),
      );
      }
     */
}